// import axios from "./index";
const axios = require("./index");

// 接受对局
module.exports.findSummoner = async (name) =>
  await axios.get("/lol-summoner/v1/summoners", {
    params: {
      name,
    },
  });
// 获取精粹
module.exports.getLolBlueEssence = async () => {
  // 蓝色精粹
  let { lol_blue_essence } = await axios.get(
    "/lol-inventory/v1/wallet/lol_blue_essence"
  );

  return lol_blue_essence;
};

// 接受对局
module.exports.confirmTheGame = async () =>
  await axios.post("/lol-matchmaking/v1/ready-check/accept");

//  自动寻找对局
module.exports.lookingForGame = async () =>
  await axios.post("/lol-lobby/v2/lobby/matchmaking/search");

// 玩家点赞
// 随机数
function randomNum(minNum, maxNum) {
  return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
}
module.exports.giveALike = async () => {
  let data = await axios.get("/lol-end-of-game/v1/eog-stats-block");

  if (!data.gameId) {
    return;
  }

  // 对局房间id
  let { gameId } = data;
  // 召唤师自己id
  let { summonerId } = data.localPlayer;

  // 队友id
  let summonerIdS = [];
  for (let i = 0; i < data.teams[0].players.length; i++) {
    const elId = data.teams[0].players[i].summonerId;
    if (elId !== summonerId) {
      summonerIdS.push(elId);
    }
  }

  let randomOne = randomNum(0, 3);
  randomOne = randomNum(0, 2);

  // 点赞类型
  //  SHOTCALLER COOL HEART OPT_OUT

  const giveThumbsUp = ["SHOTCALLER", "COOL", "HEART"];

  let result = await axios.post("/lol-honor-v2/v1/honor-player", {
    gameId,
    summonerId: summonerIdS[randomOne],
    honorCategory: giveThumbsUp[randomOne],
  });
  return result;
};

// 再来一局
module.exports.oneMoreGame = async () =>
  await axios.post("/lol-lobby/v2/play-again");
